package tt.dz.appserver.service.business.imp;

import java.util.List;

import javax.annotation.Resource;

import org.apache.avro.AvroRemoteException;

import com.alibaba.fastjson.JSONObject;

import tt.dz.appserver.dao.ext.AppFeedBackDao;
import tt.dz.appserver.entity.model.AppFeedBack;
import tt.dz.appserver.service.business.AppFeedbackService;
import tt.dz.appserver.util.date.DateUtil;
import tt.dz.appserver.util.enums.Response;

/**
 * App反馈管理实现类
 * @author USER001
 *
 */

public class AppFeedbackServiceImpl implements AppFeedbackService {

	@Resource
	private AppFeedBackDao appFeedBackDao;

	@Override
	public JSONObject appfeedbackdel(String userid, String createtime, String operid) throws AvroRemoteException {
		// TODO Auto-generated method stub
		
		AppFeedBack appFeedback = new AppFeedBack();
		JSONObject resultJsonObject = new JSONObject();
		String updatetime = DateUtil.getDateTime();
		Integer validflag = 0;		
		
		appFeedback.setUser_id(userid);
		appFeedback.setCreate_time(DateUtil.parseStringToDateTime(createtime));
		appFeedback.setUpdate_time(DateUtil.parseStringToDateTime(updatetime));
		appFeedback.setOper_id(operid);
		appFeedback.setValid_flag(validflag);
		
		appFeedBackDao.delAppFeedback(appFeedback);
		
		resultJsonObject.put("userid", userid);
		resultJsonObject.put("createtime", createtime);
		resultJsonObject.put("updatetime", updatetime);
		resultJsonObject.put("operid", operid);
		resultJsonObject.put("validflag", validflag);
		resultJsonObject.put("code", Response.SUCCESS.getCode());
		resultJsonObject.put("msg", Response.SUCCESS.getMsg());
		
		return resultJsonObject;
	}

	@Override
	public JSONObject appfeedbackupdate(String userid, String createtime, Integer disposeflag, String operid)
			throws AvroRemoteException {
		// TODO Auto-generated method stub
		
		AppFeedBack appFeedback = new AppFeedBack();
		JSONObject resultJsonObject = new JSONObject();
		String updatetime = DateUtil.getDateTime();
		Integer validflag = 1;
		
		appFeedback.setUser_id(userid);
		appFeedback.setCreate_time(DateUtil.parseStringToDateTime(createtime));
		appFeedback.setDispose_flag(disposeflag);
		appFeedback.setUpdate_time(DateUtil.parseStringToDateTime(updatetime));
		appFeedback.setOper_id(operid);
		appFeedback.setValid_flag(validflag);
		
		appFeedBackDao.UpdateAppFeedbac(appFeedback);
		
		resultJsonObject.put("userid", userid);
		resultJsonObject.put("createtime", createtime);
		resultJsonObject.put("disposeflag", disposeflag);
		resultJsonObject.put("updatetime", updatetime);
		resultJsonObject.put("operid", operid);
		resultJsonObject.put("validflag", validflag);
		resultJsonObject.put("code", Response.SUCCESS.getCode());
		resultJsonObject.put("msg", Response.SUCCESS.getMsg());
		
		return resultJsonObject;
	}

	@Override
	public List<AppFeedBack> appfeedbackselect() throws AvroRemoteException {
		// TODO Auto-generated method stub
		
		List<AppFeedBack> appFeedbackList = appFeedBackDao.findAppFeedbackValid();
				
		return appFeedbackList;
		
	}
	
}
